/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this
work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the
"License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * *
http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is
distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific
language governing permissions and * limitations under the License. */
/* eslint-disable */
<template>
  <m-list-construction title="项目级别参数">
    <template slot="operation">
      <el-button
        v-auth="['projects:definition:create']"
        type="primary"
        size="mini"
        @click="_create"
      >创建项目级别参数</el-button>
      <mCreate ref="mCreate">
      </mCreate>
    </template>
    <template slot="conditions">
      <m-conditions @on-conditions="_onConditions"> </m-conditions>
    </template>
    <template slot="content">
      <template v-if="tenementList.length || total > 0">
        <m-list
          @on-edit="_onEdit"
          @on-update="_onUpdate"
          @on-refresh="_refresh"
          :tenement-list="tenementList"
          :page-no="searchParams.pageNo"
          :page-size="searchParams.pageSize"
        >
        </m-list>
        <div class="page-box">
          <el-pagination
            background
            @current-change="_page"
            @size-change="_pageSize"
            :page-size="searchParams.pageSize"
            :current-page.sync="searchParams.pageNo"
            :page-sizes="[10, 30, 50]"
            layout="sizes, prev, pager, next, jumper"
            :total="total"
          >
          </el-pagination>
        </div>
      </template>
      <template v-if="!tenementList.length && total <= 0">
        <m-no-data></m-no-data>
      </template>
    </template>
  </m-list-construction>
</template>
<script>
  import _ from 'lodash'
  import { getOrderList } from '@/conf/home/apis'
  import mList from './_source/list'
  import mCreate from './_source/create.vue'
  import mNoData from '@/module/components/noData/noData'
  import listUrlParamHandle from '@/module/mixin/listUrlParamHandle'
  import mConditions from './_source/search.vue'
  import mListConstruction from '@/module/components/listConstruction/listConstruction'

  export default {
    name: 'orderList',
    data () {
      return {
        isShowTip: true,
        total: null,
        isLoading: true,
        tenementList: [],
        searchParams: {
          pageSize: 10,
          pageNo: 1
        },
        isLeft: true,
        createTenementDialog: false,
        item: {}
      }
    },
    mixins: [listUrlParamHandle],
    methods: {
      /**
       * Query
       */
      _onConditions (o) {
        this.searchParams = _.assign(this.searchParams, o)
        this.searchParams.pageNo = 1
        this._getList(false)
      },
      _page (val) {
        this.searchParams.pageNo = val
      },
      _pageSize (val) {
        this.searchParams.pageSize = val
      },
      _onUpdate () {
        this._debounceGET()
      },
      _create () {
        this.$refs.mCreate.show({
          id: '',
          name: '',
          value: ''
        })
      },
      onUpdate () {
        this._debounceGET('false')
        this.createTenementDialog = false
      },
      close () {
        this.createTenementDialog = false
      },
      async _getList (flag) {
        this.isLoading = !flag
        try {
          const res = await getOrderList(this.searchParams)
          if (res) {
            const { data } = res
            if (this.searchParams.pageNo > 1 && data.totalList.length === 0) {
              this.searchParams.pageNo = this.searchParams.pageNo - 1
            } else {
              this.tenementList = []
              this.tenementList = data.totalList
              this.total = data.total
              this.isLoading = false
            }
          } else {
            this.$message.warning(res.msg || '')
          }
        } catch (error) {
          console.log('error===>', error)
        } finally {
          this.isLoading = false
        }
      }
    },
    watch: {
      // router
      $route (a) {
        // url no params get instance list
        this.searchParams.pageNo = _.isEmpty(a.query) ? 1 : a.query.pageNo
      }
    },
    created () { },
    mounted () { },
    beforeDestroy () {
      sessionStorage.setItem('isLeft', 1)
    },
    components: { mCreate, mList, mListConstruction, mConditions, mNoData }
  }
</script>

<style lang="scss" scoped>
</style>
